--- import Layout from "@layouts/layout.astro"; import Nav from "@components/Nav.astro"; import KlaskBoard from "@components/KlaskBoard.astro"; import VirtualGame from "@components/VirtualGame.astro"; import { init, getGame, getUser } from "@utils/db"; import { getUserFromRequest } from "@utils/auth"; await init(); const { id } = Astro.params; if (!id) return Astro.redirect("/"); const game = await getGame(id); if (!game) { return new Response("Game not found", { status: 404 }); } const currentUserName = getUserFromRequest(Astro.request); const currentUser = currentUserName ? await getUser(currentUserName) : null; const isPlayer1 = currentUserName === game.player1; const isPlayer2 = currentUserName === game.player2; const isParticipant = isPlayer1 || isPlayer2; const canJoin = !isParticipant && game.status === "waiting" && currentUserName && currentUserName !== game.player1; const origin = new URL(Astro.request.url).origin; const gameUrl = `${origin}/game/${id}`; const isVirtual = game.mode === "virtual"; --- {isVirtual ? "🌐 Virtual" : "🏓 In Person"} {/* --- WAITING STATE (both modes) --- */} {game.status === "waiting" && ( {!isVirtual && ( )} Waiting for opponent Share this game Copy {canJoin && ( Join as {currentUserName} )} {!currentUserName && ( Sign in to join )} Created by {game.player1} )} {/* --- VIRTUAL ACTIVE GAME --- */} {isVirtual && game.status === "active" && game.player2 && ( )} {/* --- IN-PERSON ACTIVE GAME --- */} {!isVirtual && game.status !== "waiting" && game.status !== "complete" && ( ● {game.player2 ?? "Player 2"} {isPlayer2 && you} {game.score2} +1 First to 6 ● {game.player1} {isPlayer1 && you} {game.score1} +1 {isParticipant && ( End & Submit Result Ends the game and saves ratings )} {!isParticipant && ( Spectating )} )} {/* --- COMPLETE (both modes) --- */} {game.status === "complete" && ( Game Over {game.winner} wins! {game.player1} {game.score1} — {game.score2} {game.player2} New Game Home )}
Waiting for opponent
Created by {game.player1}
Ends the game and saves ratings
Spectating
Game Over